package com.example.mygame.service;

import com.example.mygame.model.BackupTask;
import com.example.mygame.model.BackupTaskDetail;
import com.example.mygame.utils.JsonUtils;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Service
public class BackupService {

    public BackupTaskDetail getDetail(String name) {
//    public List<BackupTaskDetail> getDetail(String name) {
        List<BackupTaskDetail> result = new ArrayList<>();
        BackupTask task = new BackupTask();
        BackupTaskDetail detail = new BackupTaskDetail();
        String file = "E:\\date\\file\\myGame\\backup\\" + name+ "\\" + "backupInfo.json";
        try {
            task = JsonUtils.fromJsonFile(file  , BackupTask.class);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        detail.setName(task.getList().get(0).getName());
        detail.setSize(task.getList().get(0).getSize());
        return detail;
    }
}
